import {resolve} from "path";
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import {createHtmlPlugin} from 'vite-plugin-html'
import VueSetupExtend from 'vite-plugin-vue-setup-extend'



const htmlParams = {
  minify: true,
  pages: [
      {
          filename: 'index',     // filename 默认是template文件名，就是index.html
          entry: '/src/main.ts',
          template: 'index.html',
      },
      {
        filename: 'beijing', // filename 默认是template文件名，就是beijing.html
        entry: '/src/beijing/main.ts',
        template: 'beijing.html',
      },
      {
          filename: 'nanjing',
          entry: '/src/nanjing/main.ts',
          template: 'nanjing.html',
      },
  ]
}


// https://vitejs.dev/config/
export default defineConfig({
  base: './',               // 方便打包后预览
  publicDir: 'public',      // 默认 public
  plugins: [vue(), VueSetupExtend(), createHtmlPlugin(htmlParams)],
  resolve: {
    alias: {
        '@': resolve(__dirname, 'src'),
    }
  },
  build: {
      cssCodeSplit: true,
      emptyOutDir: true,
      sourcemap: false,
      assetsDir: 'assets', // 默认 assets
      outDir: 'dist',      // 默认 dist
      rollupOptions: {
          input: {},       // input 不用管，插件内会处理
          output: {
              compact: true,
              entryFileNames: "static/js/[name]-[hash].js",
              chunkFileNames: "static/js/[name]-[hash].js",
              assetFileNames: "static/[ext]/[name].[ext]",
          }
      }
  }
})
